package com.leecode.string;

public class StringNonRepeatMaxLengthMain {
	public static void main(String[] args) {
		System.out.println(test("bbbbb"));
	}

	public static Integer test(String s) {
		if (s.length()==0) {
			return 0;
		}

		int max = 1;
		int begin = 0, end = 0;

		char[] chars = s.toCharArray();
		while (end < chars.length - 1) {
			end++;
			//每次进循环比较前,都要重置临时temp为1,
			int temp = 1;
			//end先走一步,end和[begin开始,end的前一位]的全要比较,进入循环后会使得temp增加
			for (int i = begin; i < end; i++) {
				if (chars[i] != chars[end]) {
					temp++;
					if (temp > max) {
						max = temp;
					}
				} else {
					//发现前面有一个和end相等,肯定break,但break之前要做些事情
					begin = i + 1;
					temp = end - begin + 1;
					break;
				}
			}

		}

		return max;
	}
}
